package com.topcoder.srm522;

public class CorrectMultiplication {
	public long getMinimum(int a, int b, int c) {
		long res = Long.MAX_VALUE;
		for (int i=1; i*i-i<=c; i++) {
			res = Math.min(res, check(i, c/i, a, b, c));
			res = Math.min(res, check(i, c/i+1, a, b, c));
		}
		return res;
	}
	
	private long check(int A, int B, int a, int b, int c) {
		return Math.abs(Math.min(A, B) - Math.min(a, b)) 
				+ Math.abs(Math.max(A, B) - Math.max(a, b)) +
				Math.abs(A*B - c);
	}
}
